<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>{:config('app_name')} - 管理登录</title>
	<link rel="icon" href="/bitbug_favicon.ico" type="image/x-icon" />
	<link rel="shortcut icon" href="/bitbug_favicon.ico" type="image/x-icon"/>
	<link rel="stylesheet" href="{$public}layui/css/layui.css">
	<script type="text/javascript" src="{$public}js/jquery-1.11.1.js"></script>
    <style type="text/css">
        body{background-color:#f5f5f5;}
		.login-head{position:fixed;left:0;top:0;width:80%;height:60px;line-height:60px;background:#000;padding:0 10%;}
        .login-head h1{color:#fff;font-size:20px;font-weight:600;text-align: center;}
        .login-box{margin:240px auto 0;width:400px;background-color:#fff;padding:15px 30px;border-radius:10px;box-shadow: 5px 5px 15px #999;}
        .login-box .layui-input{font-size:15px;font-weight:400}
        .login-box .layui-btn{width:100%;}
        .login-box .copyright{text-align:center;height:50px;line-height:50px;font-size:12px;color:#ccc}
        .login-box .copyright a{color:#ccc;}
		.layui-input:focus{border-color:#C9C9C9!important}
    </style>
</head>
<body>
<div class="login-head">
    <h1>{:config('title')} 管理系统</h1>
</div>
<div class="login-box">
    <form action="{:url('Login/onlogin')}" method="post" class="layui-form layui-form-pane">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>管理登录</legend>
        </fieldset>
        <div class="layui-form-item">
            <label class="layui-form-label">登录账号</label>
            <div class="layui-input-block">
                <input type="text" name="username" class="layui-input" lay-verify="required" placeholder="请输入登录账号" autofocus="autofocus" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" class="layui-input" lay-verify="required" placeholder="请输入登录密码" value="">
            </div>
        </div>
         <div class="layui-form-item">
            <label class="layui-form-label">安全验证</label>
            <div class="layui-input-inline" style="width:100px;">
                <input type="text" name="code" maxlength="6" class="layui-input" placeholder="安全验证码">
            </div>
			<img src="{:url('Login/verify',array())}" id="verifyImg" alt="点击刷新验证码" onclick="fleshVerify()" style="height: 38px;width: 180px;cursor: pointer;">
        </div>
		<input type="button" value="登录" class="layui-btn" id="sub_login">
    </form>
    <div class="copyright">
        © 2006-{:date('Y')+1} <a href="{:config('version_url')}" target="_blank">{:config('version_name')} {:config('version_num')}</a> All Rights Reserved.
    </div>
</div>
<script src="{$public}layer/layer.js"></script>
{if config('app_wy.gee_stutas') == 1}
<script src="http://static.geetest.com/static/tools/gt.js"></script>
<script>
var handler = function (captchaObj) {
	captchaObj.onReady(function () {
		$("#wait").hide();
	}).onSuccess(function () {
		var result = captchaObj.getValidate();
		if (!result) {
			return alert('请完成验证');
		}else{
			result['username'] = $("input[name='username']").val();
			result['password'] = $("input[name='password']").val();
			result['code'] = $("input[name='code']").val();
			sub_onlogin(result);
		}
	});
	$(".layui-btn").click(function(){
		$("#sub_login").attr("disabled",true);
		var username = $("input[name='username']").val();
		var password = $("input[name='password']").val();
		var code = $("input[name='code']").val();
		if(!username){
			$("input[name='username']").focus();
			$("#sub_login").attr("disabled",false);
			layer.msg("登录账号不能为空！");
			return;
		}
		if(!password){
			layer.msg("登录密码不能为空！");
			$("#sub_login").attr("disabled",false);
			return;
		}
		if(!code){
			layer.msg("验证码不能为空！");
			$("#sub_login").attr("disabled",false);
			return;
		}
		captchaObj.verify();
	});
};
$.ajax({
	url: "{:url('Login/gee_verify')}?t=" + (new Date()).getTime(),
	type: "get",
	dataType: "json",
	success: function (data) {
		initGeetest({
			gt: data.gt,
			challenge: data.challenge,
			offline: !data.success,
			new_captcha: data.new_captcha,
			product: "bind",
			width: "300px"
		}, handler);
	}
});
</script>
{else/}
<script>
$(".layui-btn").click(function(){
	$("#sub_login").attr("disabled",true);
	var username = $("input[name='username']").val();
	var password = $("input[name='password']").val();
	var code = $("input[name='code']").val();
	if(!username){
		layer.msg("登录账号不能为空！");
		$("#sub_login").attr("disabled",false);
		return;
	}
	if(!password){
		layer.msg("登录密码不能为空！");
		$("#sub_login").attr("disabled",false);
		return;
	}
	if(!code){
		layer.msg("验证码不能为空！");
		$("#sub_login").attr("disabled",false);
		return;
	}
	var str_arr = {
			'username':username,
			'password':password,
			'code':code,
		};
	sub_onlogin(str_arr);
});
</script>
{/if}
<script>
function sub_onlogin(str_arr){
console.log(str_arr);
	var index = layer.load(1, {
		shade: [0.3,'#000']
	});
	$.post("{:url('Login/onlogin')}",str_arr,function(data){
		if(data.code == 1){
			window.location.href = data.url;
		}else{
			fleshVerify();
			layer.close(index); 
			layer.msg(data.msg);
			$("#sub_login").attr("disabled",false);
		}
	},"JSON");
}
function fleshVerify(){ 
	var time = new Date().getTime();
	document.getElementById("verifyImg").src="{:url('Login/verify',array())}?v="+time;
}
</script>
</body>
</html>